package com.example.springboot.mapper;

import com.example.springboot.pojo.Notice;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NoticeMapper {

    @Select("select * from notice where id=#{id}")
    Notice findById(Integer id);

    @Insert("insert into notice(tittle,type,content,status,time)" +
            " values(#{tittle},#{type},#{content},#{status},#{time})")
    void addNotice(String tittle, String content, String type, Integer status, String time);

    @Update("update notice set status=1,time=#{time} where id=#{id}")
    void publish(Integer id,String time);

    @Select("select id,tittle,type,status,time from notice order by time desc")
    List<Notice> getList();

    @Delete("delete from notice where id=#{id}")
    void deleteNotice(Integer id);

    @Update("update notice set tittle=#{tittle},type=#{type},content=#{content},time=#{time} where id=#{id}")
    void updateNotice(Integer id, String tittle, String type, String content, String time);

    @Select("select id,tittle,time from notice where status=1 and type=#{type} order by time desc")
    List<Notice> getByType(String type);
}
